import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'
axios.defaults.baseURL = 'http://yuenov.com:15555';

Vue.use(Vuex);
import localrequest from '../assets/localapi/fake.js';


export default new Vuex.Store({
  state: {
    imgbaseUrl: "http://pt.yuenov.com:17777",
    discoverylist: [],
    RankerBoy: [],
    RankerGirl: [],
    localbooks: []
  },
  mutations: {

    updatedDiscovery(state) {
      // console.log('提交成功');
      // 获取发现页面数据
      axios({
        method: "GET",
        url: '/app/open/api/category/discovery',
      }).then(result => {
        console.log('获取书城数据==>', result);

        if (result.data.data.list) {
          state.discoverylist = result.data.data.list;
          // console.log('lists  2==>', this.lists);
        }
      }).catch(err => {
        console.log(err);
      })

    },
    updatedRanker(state) {
      axios({
        method: "GET",
        url: "/app/open/api/rank/getList",
        // 参数非必须
        params: {
          channels: 1
          // 1, 1, '男生频道'
          // ranks: List类型 榜单信息列表
          // channelId: Integer类型 频道号 ：1为男生 ，2 为女生
          // channelName: String类型 频道名称
        }
      }).then(res => {
        console.log("Rand=>", res);
        if (res.data.result.code === 0) {
          console.log('updatedRanker', res.data.result.msg);

          state.RankerBoy = res.data.data.channels[0];
          state.RankerGirl = res.data.data.channels[1];
        }
      })
    },
    // 获取本地数据测试
    getlocaltionbooks(state) {
      localrequest.getData('books.json')
        .then(res => {
          console.log('本地书籍数据 =>', res);
          console.log(typeof (res.data));
          state.localbooks = res.data;
          localStorage.setItem('_mybooks',state.localbooks);
        });

    }

  },
  actions: {
    updatedDiscovery(context) {
      // console.log(context);
      context.commit('updatedDiscovery');
    },
    getlocaltionbooks({commit}){
      commit('getlocaltionbooks');
    }
  },
  modules: {}
})